<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title><tiles:insertAttribute name="title" ignore="true" /></title>
	
	<!-- CSS Reset -->
	<link rel="stylesheet" type="text/css" media="screen" href="<c:url value="/resources/css/reset.css"/>" />
	
	<!-- Fluid 960 Grid System - CSS framework -->
	<link rel="stylesheet" type="text/css" media="screen" href="<c:url value="/resources/css/grid.css"/>" />
	
	<!-- IE Hacks for the Fluid 960 Grid System -->
	<!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="<c:url value="/resources/css/ie6.css"/>" /><![endif]-->
	<!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="<c:url value="/resources/css/ie.css"/>" /><![endif]-->
	
	
	<link rel="stylesheet" href="<c:url value="/resources/css/ui-lightness/jquery-ui-1.8.23.custom.css"/>" type="text/css" />
	
	<!-- Main stylesheet -->
	<link rel="stylesheet" type="text/css" media="screen" href="<c:url value="/resources/css/styles.css"/>" />
	
	<!-- Table sorter stylesheet -->
	<!-- link rel="stylesheet" type="text/css" media="screen" href="<c:url value="/resources/css/tablesorter.css"/>" / -->
	<link rel="stylesheet" type="text/css" media="screen" href="<c:url value="/resources/css/jquery.dataTables.css"/>" />
	
	<!-- Thickbox stylesheet 
	<link rel="stylesheet" type="text/css" media="screen" href="<c:url value="/resources/css/thickbox.css"/>" />
	-->
	
	<!-- Themes. Below are several color themes. 
	<link rel="stylesheet" type="text/css" media="screen" href="<c:url value="/resources/css/theme-blue.css"/>" />
	-->
	
	<style>
		.validateTips { border: 1px solid transparent; padding: 0.3em; margin-bottom:8px; }
		input.text { margin-bottom:5px; padding: .2em; }
		label { margin-bottom:0px; }
		fieldset { margin-bottom:0; margin-top:5px; }
		.sorting_disabled { text-align: left}
	</style>
	
	
	<!-- JQuery engine script-->
	<script type="text/javascript" src="<c:url value="/resources/js/jquery-1.8.0.min.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/resources/js/jquery-ui-1.8.23.custom.min.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/resources/js/jquery.dataTables.min.js"/>"></script>
	
	<!-- JQuery tablesorter plugin script-->
	<script type="text/javascript" src="<c:url value="/resources/js/jquery.tablesorter.min.js"/>"></script>
	
	<!-- JQuery pager plugin script for tablesorter tables -->
	<script type="text/javascript" src="<c:url value="/resources/js/jquery.tablesorter.pager.js"/>"></script>
	
	<!-- JQuery thickbox plugin script 
	<script type="text/javascript" src="<c:url value="/resources/js/thickbox.js" />"></script>
	-->
	
	<script type="text/javascript">
		$(document).ready(function() {
			$("input:submit, button").button();
			
			 $( "input:checkbox" ).button({
			        icons: { primary: "ui-icon-close" },
			        text: true
			    }).click(function() {
			        if($( this ).attr('checked')){
			            $( this ).button("option", {
			              icons: { primary: "ui-icon-check" }
			            });                
			        }else{
				        $( this ).button("option", {
				          icons: { primary: "ui-icon-close" }
				        });
			        }
			    });
			    //alert($( "input:checkbox" ).length);
			    $.each($( "input:checkbox" ), function(index, item){
			        if($(item).attr('checked')){
			            $( item ).button("option", {
			              icons: { primary: "ui-icon-check" }
			            });
			        }else{
			            $( item ).button("option", {
			              icons: { primary: "ui-icon-close" }
			            });
			        }           
			    });  
		});
		
////////////////////////////////////////////
////////////////////////////////////////////
		
		// UTILS FUNCTIONS
		
		function refreshCheckbox( item){
			$(item).button("refresh");
			if($(item).attr('checked')){
	            $(item).button("option", {
	              icons: { primary: "ui-icon-check" }
	            });
	        }else{
	            $(item).button("option", {
	              icons: { primary: "ui-icon-close" }
	            });
	        }
		}
		
		
		//Addidn functions to datatable
		$.fn.dataTableExt.oApi.fnResetAllFilters = function (oSettings, bDraw/*default true*/) {
	        for(iCol = 0; iCol < oSettings.aoPreSearchCols.length; iCol++) {
	                oSettings.aoPreSearchCols[ iCol ].sSearch = '';
	        }
	        oSettings.oPreviousSearch.sSearch = '';
	 
	        if(typeof bDraw === 'undefined') bDraw = true;
	        if(bDraw) this.fnDraw();
		};
		
		// Form validation functions
		function checkRegexp( o, regexp, n ) {
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass( "ui-state-error" );
				updateTips( n );
				return false;
			} else {
				return true;
			}
		}
		
		function checkLength( o, n, min, max ) {
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass( "ui-state-error" );
				updateTips( "La cantidad de caracteres de " + n + " debe ser entre " +
					min + " y " + max + "." );
				return false;
			} else {
				return true;
			}
		}
		
		function updateTips( t ) {
			var tips = $(".validateTips");
			tips.text(t).addClass( "ui-state-highlight" );
			setTimeout(function() {
				tips.removeClass( "ui-state-highlight", 1500 );
			}, 500 );
		}
		
		function checkRegexp( o, regexp, n ) {
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass( "ui-state-error" );
				updateTips( n );
				return false;
			} else {
				return true;
			}
		}
		
		// Alerts
		function customAlert(message){
			$("#customAlertMessage_text").html(message);
			$( "#customAlertMessage").dialog({
				height: 140,
				modal: true,
				buttons: {
					"Aceptar" : function () {
						$(this).dialog("close");
					}
				}
			});
		}
		
		function customConfirmation(message, aceptFunction, cancelFunction){
			var retorno;
			$("#customConfirmationMessage_text").html(message);
			$( "#customConfirmationMessage" ).dialog({
				resizable: false,
				height:140,
				modal: true,
				buttons: {
					"Aceptar": function() {
						aceptFunction();
						$(this).dialog("close");
					},
					"Cancelar": function() {
						cancelFunction();
						$(this).dialog("close");
					}
				}
			});
			return retorno;
		}
		
		(function( $ ) {
			$.widget( "ui.combobox", {
				_create: function() {
					var input,
						self = this,
						select = this.element.hide(),
						selected = select.children( ":selected" ),
						value = selected.val() ? selected.text() : "",
						wrapper = this.wrapper = $( "<span>" )
							.addClass( "ui-combobox" )
							.insertAfter( select );

					input = $( "<input>" )
						.appendTo( wrapper )
						.val( value )
						.addClass( "ui-state-default ui-combobox-input" )
						.autocomplete({
							delay: 0,
							minLength: 0,
							source: function( request, response ) {
								var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
								response( select.children( "option" ).map(function() {
									var text = $( this ).text();
									if ( this.value && ( !request.term || matcher.test(text) ) )
										return {
											label: text.replace(
												new RegExp(
													"(?![^&;]+;)(?!<[^<>]*)(" +
													$.ui.autocomplete.escapeRegex(request.term) +
													")(?![^<>]*>)(?![^&;]+;)", "gi"
												), "<strong>$1</strong>" ),
											value: text,
											option: this
										};
								}) );
							},
							select: function( event, ui ) {
								ui.item.option.selected = true;
								self._trigger( "selected", event, {
									item: ui.item.option
								});
								 select.trigger("change");
							},
							change: function( event, ui ) {
								if ( !ui.item ) {
									var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
										valid = false;
									select.children( "option" ).each(function() {
										if ( $( this ).text().match( matcher ) ) {
											this.selected = valid = true;
											return false;
										}
									});
									if ( !valid ) {
										// remove invalid value, as it didn't match anything
										$( this ).val( "" );
										select.val( "" );
										input.data( "autocomplete" ).term = "";
										return false;
									}
								}
							}
						})
						.addClass( "ui-widget ui-widget-content ui-corner-left" );

					input.data( "autocomplete" )._renderItem = function( ul, item ) {
						return $( "<li></li>" )
							.data( "item.autocomplete", item )
							.append( "<a>" + item.label + "</a>" )
							.appendTo( ul );
					};

					$( "<a>" )
						.attr( "tabIndex", -1 )
						.attr( "title", "Show All Items" )
						.appendTo( wrapper )
						.button({
							icons: {
								primary: "ui-icon-triangle-1-s"
							},
							text: false
						})
						.removeClass( "ui-corner-all" )
						.addClass( "ui-corner-right ui-combobox-toggle" )
						.click(function() {
							// close if already visible
							if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
								input.autocomplete( "close" );
								return;
							}

							// work around a bug (likely same cause as #5265)
							$( this ).blur();

							// pass empty string as value to search for, displaying all results
							input.autocomplete( "search", "" );
							input.focus();
						});
				},

				destroy: function() {
					this.wrapper.remove();
					this.element.show();
					$.Widget.prototype.destroy.call( this );
				}
			});
		})(jQuery);
	</script>
</head>
<body>
	<tiles:insertAttribute name="header" />
	
	<!-- Common utils (+) -->
	<div id="customAlertMessage" title="Atencion!" style="display:none">
		<p id="customAlertMessage_text">Mensaje del popup</p>
	</div>
	<div id="customConfirmationMessage" title="Mensaje de confirmacion" style="display:none">
		<p id="customConfirmationMessage_text">Mensaje del popup</p>
	</div>
    <div class="container_12">
        <tiles:insertAttribute name="body"/>
        <div style="clear:both;"></div>
    </div>
    <!-- Common utils (-) -->
	
    <div style="clear:both;"></div>
    <tiles:insertAttribute name="footer" />
</body>
</html>